package br.edu.ifrn.tads.rettiwt.servlets;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.ietf.jgss.Oid;

import br.edu.ifrn.tads.rettiwt.RettiwtInterface;
import br.edu.ifrn.tads.rettiwt.beans.Mensagem;
import br.edu.ifrn.tads.rettiwt.beans.Usuario;
import br.edu.ifrn.tads.rettiwt.beans.dao.MensagemDAO;
import br.edu.ifrn.tads.rettiwt.beans.dao.UsuarioDAO;

import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Logger;

import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

/**
 * Servlet implementation class Visualizar
 */
public class Visualizar extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private static final Logger log = Logger.getLogger(Cadastramento.class.getName());
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Visualizar() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
		
		UserService userService = UserServiceFactory.getUserService();
		User user = userService.getCurrentUser();

		UsuarioDAO dao = UsuarioDAO.obterUsuarioDao();
		MensagemDAO msg = MensagemDAO.obterMensagemDAO();
		
		Usuario usuario = dao.getUsuarioByEmail(user.getEmail());
		
				
		List<Mensagem> lista = msg.getMensagemByID(usuario.getId());
		
		request.setAttribute("mensagens", lista);
		
		
				
		RequestDispatcher dispatcher = request.getRequestDispatcher("/main");
		dispatcher.forward(request, response);
	}


	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	}
}



